/*

	This file loads data from the statistics for Manufacturers' Sales of Goodst (abbreviated VARS by DST)
	i.e. the Danish Prodcom register

*/

cd ${work}1_data

local start	1995
local end	2015
local list	"jurnr periode rapport_id saflbnr varenr vaerdi maengde mgd_tekst"
local list1	"fag_hoved_bra_db07"


*LOAD
foreach y of numlist `start'/`end' {
	
	use input\vars`y' , clear	
	
	if inrange(`y',`start',1999)	keep `list'
	if inrange(`y',2000,`end')		keep `list' `list1'
	
	cap destring maengde, replace
	
	save temp\vars_`y', replace	

}

clear
local command use
foreach y of numlist `start'/`end' {
	`command' temp\vars_`y'
	erase temp\vars_`y'.dta
	local command "append using"
}

*MODIFY
rename varenr vnr
rename rapport_id rapid
rename maengde mgd
rename vaerdi vrd
rename fag_hoved_bra_db07 db07

gen year=year(periode)
gen quarter=quarter(periode)
drop periode
egen date=group(year quarter)

replace jurnr="" if real(jurnr)==.

*SAVE
order jurnr vnr date
sort jurnr vnr date
compress
save output\vars_ipt, replace